package main

import (
	"context"
	"github.com/spf13/pflag"
	"github.com/spf13/viper"
	"net/http"
)

func main() {
	initViper()
	app := InitPaymentServiceServer()
	app.Cron.Start()

	go func() {
		err := app.Server.Serve()
		if err != nil {

		}
	}()

	server := http.Server{
		Addr:    ":8090",
		Handler: app.Web.Handler(),
	}
	server.ListenAndServe()

	ctx := app.Cron.Stop()
	<-ctx.Done()
	server.Shutdown(context.Background())
}
func initViper() {
	cFile := pflag.String("config", "webook/payment/config/dev.yaml", "指定配置文件路径")
	pflag.Parse()
	viper.SetConfigFile(*cFile)

	if err := viper.ReadInConfig(); err != nil {
		panic(err)
	}
}
